/**
* Author: fulishang
* Create Time  : 2016年8月4日,下午9:58:29
* Modify Time :
* Desc  : 
*/
package com.sam.si.file.filter;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.integration.file.filters.AbstractFileListFilter;

public class LastModifiedFileFilter extends AbstractFileListFilter<File> {

	private final Logger LOGGER = Logger.getLogger(LastModifiedFileFilter.class);

	private final Map<String, Long> files = new HashMap<>();
	private final Object monitor = new Object();

	@Override
	protected boolean accept(File file) {
		synchronized (this.monitor) {
			Long previousModifiedTime = files.put(file.getName(), file.lastModified());
			LOGGER.info("File previous Modified Time is " + previousModifiedTime);
			return previousModifiedTime == null || previousModifiedTime != file.lastModified();
		}
	}
}